<?php

//Enbart köra om ej tidigare fel
if( !isset($_SESSION['error']) ) {
        //Enbart om kerberos-kdc är installerad
        if( is_dir( '/etc/krb5kdc' ) ) {
                $name = strtolower($_POST['name']);
                $passwd = $_POST['pass1'];

                //skapar kerberoslösen med kadmin.local
                $descriptorspec = array(
                   0 => array("pipe", "r"),  // stdin
                   1 => array("pipe", "w"),  // stdout
                   2 => array("pipe", "w")   // stderr
                );
                $process = proc_open('exec /usr/sbin/kadmin.local -q "ank '.$name.'"', $descriptorspec, $pipes, "/");
                fwrite($pipes[0], $passwd . "\n");
                fwrite($pipes[0], $passwd . "\n");
                $stout_str = stream_get_contents($pipes[1]);
                $sterr_str = stream_get_contents($pipes[2]);
                fclose($pipes[0]);
                fclose($pipes[1]);
                fclose($pipes[2]);
                $exitCode = proc_close($process);
                if( $exitCode !== 0 && strlen($sterr_str) !== 0 ) {
                        //echo "FAIL: $stout_str\n$sterr_str\n";
                        error('unknown');
                }
        }
}
?>
